package com.mydemo.proxy;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;

/**
 * <p></p >
 *
 * @author liming1
 * @version $Id: CglibHandler, v1.0 2019-09-11 9:59 liming1 Exp $
 */
public class CglibHandler {
    public void test(){
        System.out.println("我是cglib测试");
    }
    public static void main(String[] args) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(CglibHandler.class);
        enhancer.setCallback((MethodInterceptor) (o, method, objects, methodProxy) -> {
            System.out.println("开始拦截");
            Object result = methodProxy.invokeSuper(o, objects);
            System.out.println("拦截结束");
            return result;
        });

        CglibHandler o = (CglibHandler)enhancer.create();
        o.test();
    }
}
